package com.yenlien.traceyun.breed.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.breed.entity.Recall;
import com.yenlien.traceyun.breed.service.RecallService;
import com.yenlien.traceyun.webase.controller.BaseController;

/**
 * 召回控制层
 *
 * @author maybe
 * @date 2020年9月29日
 */
//@RestController
//@RequestMapping("/recall")
public class RecallController extends BaseController {
    @Autowired
    private RecallService recallService;

    //分页查询
    @RequestMapping(value = "/findByList", method = RequestMethod.POST)
    public Object findByList(@RequestBody JSONObject params) {
        Recall recall = new Recall();
        recall.setSeedName(params.getString("searchName"));
        recall.setBatch(params.getString("searchName"));
        recall.setRecallUser(params.getString("searchName"));
        recall.setPage(params.getIntValue("page"));
        return buildPage(recallService.findByList(recall));
    }

    //新增召回
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Object save(@RequestBody Recall recall) {
        recallService.save(recall);
        return success("success");
    }

    //根据ID查询详情
    @RequestMapping(value = "/findById/{id}", method = RequestMethod.GET)
    public Object findById(@PathVariable("id") String id) {
        return success(recallService.findById(id));
    }
}
